package howe.sudoku.listener;

import howe.sudoku.layout.R;
import howe.sudoku.layout.KeypadDialog;
import howe.sudoku.layout.PuzzleView;
import android.view.View;
import android.view.View.OnClickListener;

public class KeypadListener implements OnClickListener {

    private KeypadDialog keypadDialog = null;

    private PuzzleView puzzleView = null;

    public KeypadListener(KeypadDialog keypadDialog,
                          PuzzleView puzzleView) {
        this.keypadDialog = keypadDialog;
        this.puzzleView = puzzleView;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.keypad_clear :
                returnResult(0);
                break;
            default :
                this.keypadDialog.dismiss();
                break;
        }
    }

    private void returnResult(int tile) {
        puzzleView.setSelectedTile(tile);
        this.keypadDialog.dismiss();
    }
}
